package edu.cwnu.enterprisemanagement.exception;

import edu.cwnu.enterprisemanagement.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
public class GlobalException {

    public static final String USER_NOT_LOGIN = "用户未登录";
    public static final String USER_NOT_EXIST = "用户不存在";
    public static final String USERNAME_OR_PASSWORD_ERROR = "用户名或密码错误";
    public static final String USER_ALREADY_EXIST = "用户已存在";
    public static final String  USER_NAME_EMPTY= "用户名为空";
    public static final String USER_PASSWORD_EMPTY = "用户密码为空";
    @ExceptionHandler(value = Exception.class)
    public <T>Result<T> error(Exception e) {
        log.error("系统异常：{}", e.getMessage(), e);

        return Result.error("服务器内部错误");
    }
    
    @ExceptionHandler(value = BusinessException.class)
    public <T>Result<T> businessError(BusinessException e) {
        log.error("业务异常：{}", e.getMessage());
        
        return Result.error(e.getCode(), e.getMessage());
    }
}